<?php
header('Access-Control-Allow-Origin:*');  //支持全域名访问，不安全，部署后需要固定限制为客户端网址
header('Access-Control-Allow-Methods:POST,GET,OPTIONS,DELETE'); //支持的http 动作
header('Access-Control-Allow-Headers:x-requested-with,content-type');  //响应头 请按照自己需求添加。
$conn = mysqli_connect("localhost","root","","fruit");
$conn->query("set names utf8");
$type=$_GET["type"];
switch ($type) {
	case 'classList':
				// 1
		$sql1 = "SELECT * FROM product WHERE type1='进口水果'";
		$ret1 = $conn->query($sql1);

		$arr1 = array();
		while ($row1 = $ret1->fetch_assoc()) {
			$arr1[] = $row1;
		}
		$str1 = json_encode($arr1);

		// 2
		$sql2 = "SELECT * FROM product WHERE type1='国产水果'";
		$ret2 = $conn->query($sql2);

		$arr2 = array();
		while ($row2 = $ret2->fetch_assoc()) {
			$arr2[] = $row2;
		}
		$str2 = json_encode($arr2);

		// 3
		$sql3 = "SELECT * FROM product WHERE type1='精选肉类'";
		$ret3 = $conn->query($sql3);

		$arr3 = array();
		while ($row3 = $ret3->fetch_assoc()) {
			$arr3[] = $row3;
		}
		$str3 = json_encode($arr3);

		// 4
		$sql4 = "SELECT * FROM product WHERE type1='禽类蛋品'";
		$ret4 = $conn->query($sql4);

		$arr4 = array();
		while ($row4 = $ret4->fetch_assoc()) {
			$arr4[] = $row4;
		}
		$str4= json_encode($arr4);

		// 5
		$sql5 = "SELECT * FROM product WHERE type1='海鲜水产'";
		$ret5 = $conn->query($sql5);

		$arr5 = array();
		while ($row5 = $ret5->fetch_assoc()) {
			$arr5[] = $row5;
		}
		$str5 = json_encode($arr5);

		// 6
		$sql6 ="SELECT * FROM product WHERE type1='乳品糕点'";
		$ret6 = $conn->query($sql6);

		$arr6 = array();
		while ($row6 = $ret6->fetch_assoc()) {
			$arr6[] = $row6;
		}
		$str6 = json_encode($arr6);

		// 7
		$sql7= "SELECT * FROM product WHERE type1='新鲜蔬菜'";
		$ret7 = $conn->query($sql7);

		$arr7 = array();
		while ($row7 = $ret7->fetch_assoc()) {
			$arr7[] = $row7;
		}
		$str7 = json_encode($arr7);

		// 8
		$sql8 = "SELECT * FROM product WHERE type1='方便速食'";
		$ret8 = $conn->query($sql8);

		$arr8 = array();
		while ($row8 = $ret8->fetch_assoc()) {
			$arr8[] = $row8;
		}
		$str8 = json_encode($arr8);

		// 9
		$sql9 = "SELECT * FROM product WHERE type1='粮油杂货'";
		$ret9 = $conn->query($sql9);

		$arr9 = array();
		while ($row9 = $ret9->fetch_assoc()) {
			$arr9[] = $row9;
		}
		$str9= json_encode($arr9);

		// 10
		$sql10 ="SELECT * FROM product WHERE type1='饮料酒水'";
		$ret10 = $conn->query($sql10);

		$arr10 = array();
		while ($row10 = $ret10->fetch_assoc()) {
			$arr10[] = $row10;
		}
		$str10 = json_encode($arr10);

		echo '{"t1":'.$str1.',"t2":'.$str2.',"t3":'.$str3.',"t4":'.$str4.',"t5":'.$str5.',"t6":'.$str6.',"t7":'.$str7.',"t8":'.$str8.',"t9":'.$str9.',"t10":'.$str10.'}';
		break;
	case '':
	
		break;

}

?>
